<?php

namespace app\merchant\controller;

use app\common\model\MerchantBillModel;
use think\Request;

class MerchantBill extends Common
{

    public $merchantBill;

    public function __construct(Request $request,MerchantBillModel $merchantBillModel)
    {
        parent::__construct($request);
        $this->merchantBill = $merchantBillModel;
    }

    public function index (Request $request)
    {
        $search = $request->param();
        $search['merchant_id'] = session('merchant.merchant_id');
        if (!isset($search['time'])) {
            $thisMonth = date("Y-m",time());
            $search['time'] = date("Y-m",strtotime("$thisMonth -1 month"));  //默认查上个月时间
        }
        $startTime = date('Y-m-01 00:00:00', strtotime('1 month',strtotime($search['time'])));
        $endTime = date('Y-m-d 23:59:59', strtotime("$startTime +1 month -1 day"));
        $search['start_time'] = strtotime($startTime);
        $search['end_time'] = strtotime($endTime);
        $data = $this->merchantBill->search($search);
        return view('index',[
            'data' => $data,
            'search' => $search
        ]);
    }
}
